using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace IEeee
{
    public partial class CredentialsDialog : Form
    {
        public CredentialsDialog()
        {
            InitializeComponent();
        }

        public ICredentials Credentials
        {
            get
            {
                return new NetworkCredential(UserName, Password, Domain);
            }
        }

        public String UserName
        {
            get { return txtUserName.Text; }
        }

        public String Password
        {
            get { return txtPassword.Text; }
        }

        public String Domain
        {
            get { return txtDomain.Text; }
        }

        private void CredentialsDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (txtUserName.Text == "") {
                    ValidateMessageBox("User Name");
                    e.Cancel = true;
                
                } else if (txtPassword.Text == "") {
                    ValidateMessageBox("Password");
                    e.Cancel = true;
                }
            }
        }

        private void ValidateMessageBox(String fieldName)
        {
            String msg = String.Format ("Please provide a {0}.", fieldName);
            MessageBox.Show(this, msg, "IEeee!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}